/**
 * witUI 跨平台UI框架
 * @date: 2022.03.23
 * @author：taiping
 * @update: 2022.06.03
 */
import type { App } from 'vue';
import { errLog } from '@/witUI/log/errLog';
import { nextTick } from 'vue'
import {useErrorLog} from '@/store/pinia/modules/errorLog'

const store = useErrorLog();
export default function wit(app: App<Element>) {
    errLog(app);
    // 获取状态栏高度
    uni.getSystemInfo({
        success: e => {
            nextTick(() => {
                store.setSystemInfo(e);
            })
            const {statusBarHeight, platform, titleBarHeight, windowWidth} = e
            let StatusBar = statusBarHeight;
            let CustomBar = statusBarHeight ? statusBarHeight : 50
            // #ifndef MP
            if (platform == 'android') {
                // @ts-ignore
                let CustomBar = statusBarHeight + 50;
            } else {
                // @ts-ignore
                let CustomBar = statusBarHeight + 45;
            }
            // #endif
            // #ifdef MP-WEIXIN
            // @ts-ignore
            let custom = wx.getMenuButtonBoundingClientRect();
            // @ts-ignore
            CustomBar = custom.bottom + custom.top - statusBarHeight;
            // #endif
            // #ifdef MP-ALIPAY
            // @ts-ignore
            CustomBar = statusBarHeight + titleBarHeight;
            // #endif
            app.config.globalProperties.$StatusBar = StatusBar
            app.config.globalProperties.$CustomBar = CustomBar
            app.config.globalProperties.$WitWidth = windowWidth
        }
    })
}

export {
    wit
}
